package com.heiye.auth.rpc;

import com.heiye.framework.common.response.Response;
import com.heiye.user.api.api.UserFeignApi;
import com.heiye.user.api.dto.req.RegisterUserReqDTO;
import com.heiye.user.api.dto.resp.RegisterUserRspDTO;
import jakarta.annotation.Resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * @author: heiye
 * @date: 2024/09/29 下午4:36
 * @version: v1.0.0
 * @description: 用户调用层
 */
@Component
public class UserRpcService {

    private static final Logger log = LoggerFactory.getLogger(UserRpcService.class);

    @Resource
    private UserFeignApi userFeignApi;

    /**
     * 用户注册
     *
     * @param identifier
     * @return
     */
    public RegisterUserRspDTO register(String identifier, Integer type) {
        // 构建dto
        RegisterUserReqDTO registerUserReqDTO = new RegisterUserReqDTO(identifier, type);

        // 调用user服务
        Response<RegisterUserRspDTO> response = userFeignApi.userRegister(registerUserReqDTO);

        log.info("==> Auth success: {}", response.isSuccess());

        log.info("==> Auth registerUserRespDTO: {}", response.getData());

        // 校验参数
        if (!response.isSuccess()) {
            return null;
        }

        return response.getData();
    }
}
